package com.efast.dmom.aps.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.efast.dmom.aps.bean.ResultBean;
import com.efast.dmom.aps.bean.Route;
import com.efast.dmom.aps.bean.RouteAccept;
import com.efast.dmom.aps.service.RouteService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author Aaron Liu
 * @version Creation Time：2020年2月4日 下午3:55:20
 */

@RestController
@Api(tags = "Route Modeling")
@RequestMapping("/route")
public class RouteController {

	@Autowired
	RouteService routeService = null;

	@ApiOperation(value = "保存Route对象")
	@RequestMapping(value = "/saveRoute")
	public @ResponseBody ResultBean saveRoute(@RequestBody Route route) {
		
		routeService.saveRoute(route);
		
		return new ResultBean(true, "保存成功");
	}
	
	@ApiOperation(value = "删除Route对象")
	@RequestMapping(value = "/removeRouteById")
	public @ResponseBody ResultBean removeRouteById(@RequestBody RouteAccept routeData) {
		routeService.removeRoute(routeData.getId());
		
		return new ResultBean(true, "删除成功");
	}
	
	@ApiOperation(value = "初始化创建Route对象")
	@RequestMapping(value = "/createRoute")
	public @ResponseBody ResultBean createRoute(@RequestBody RouteAccept routeData) {
		
		ResultBean resultBean = new ResultBean(true);
		
//		boolean isExsit = routeService.isRouteExist(routeData.getName());
//		if(isExsit){
//			resultBean.setSuccess(false);
//			resultBean.setMessage("已经存在相同名称的Route[" + routeData.getName() + "] 请重新命名" );
//			
//			return resultBean;
//		}
		
		Route route = routeService.createRoute(routeData.getName());
		resultBean.setObject(route);
		
		return resultBean;
	}
	
}
